﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Bussiness.Manager;
using Bussiness;

public partial class News_Control_News : System.Web.UI.UserControl
{

    public Guid CategoryId 
    {
        get { return !string.IsNullOrEmpty(Request["idCat"]) ? new Guid(Request["idCat"]) : Guid.Empty; }
    }

    public Int32 IntId
    {
        get { return !string.IsNullOrEmpty(Request["ID"]) ? Int32.Parse(Request["ID"]) : -1; }
    
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Pager1.ChangePage += new EventHandler(Pager1_ChangePage);
            if (IntId == -1)
                LoadTopNews();
            else
                LoadNewsListByIntId();
        }
    }

    void Pager1_ChangePage(object sender, EventArgs e)
    {
        LoadNewsListByIntId();
    }

    void LoadNewsListByCat()
    {
        DataTable dtNewsList = CmsNewsManager.CreateInstant().getNewsListByCategory(CategoryId);
        if (dtNewsList.Rows.Count >= 0)
        {
            Pager1.DataSource = dtNewsList.DefaultView;
            Pager1.BindToControl = rep;
            rep.DataSource = dtNewsList;
            rep.DataBind();
        }
    }

    void LoadNewsListByIntId()
    {
        if (IntId != -1)
        {
            DataTable dtListNews = CmsNewsManager.CreateInstant().getNewsListByIntId(IntId);
            if (dtListNews.Rows.Count >= 0)
            {
                Pager1.DataSource = dtListNews.DefaultView;
                Pager1.BindToControl = rep;
                rep.DataSource = dtListNews;
                rep.DataBind();
            }
        }
    }

    void LoadTopNews()
    {
        DataTable dtNewsRan = CmsNewsManager.CreateInstant().getTopNews();
        if (dtNewsRan.Rows.Count >= 0)
        {
            Pager1.DataSource = dtNewsRan.DefaultView;
            Pager1.BindToControl = rep;
            rep.DataSource = dtNewsRan;
            rep.DataBind();
        }
    }
    
}
